package org.test;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Vector;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MessageServlet extends HttpServlet {
  //Process the HTTP Get request
	public void doGet(HttpServletRequest request,HttpServletResponse response) throws
	ServletException,IOException{
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out=response.getWriter();
	    out.println("<html>");
	    out.println("<link rel='Stylesheet' href='"+request.getContextPath()+"/css/style1.css' type='text/css'>");
	    out.println("<head><title>MessageServlet</title></head>");
	    out.println("<body bgcolor='#f8f8f8'>");
	    out.println("<div class='content center'>");
	    out.println("<div  style='margin: 0px auto;background-color:#fff;border: 2px solid #fff;width:900px;height:500px'>");
	    out.println("<iframe frameborder='0' height='300' width='900' ' marginHeight='0' "+"" +
	    		"scrolling=auto src='/MyChat/servlet/DispServlet' width='100%' height='80%'>");
	    out.println("</iframe>");
	    out.println("<div style='width: 300px;margin: 30px auto;position: relative'>");
	    request.setCharacterEncoding("UTF-8");
	    ServletContext context=getServletContext();
	    //获取表单信息参数
	    String usr=request.getParameter("me");
	    String str=request.getParameter("message");
	    Vector hsh=(Vector)context.getAttribute("messagelist");
	    if(str!=null){
	    	hsh.add(usr+":"+str);
	    }
	    out.println("<form method='post' action='/MyChat/servlet/MessageServlet?me="+usr+"'>");
	    out.println("<input type='text' name='message' placeholder='发送信息' autocomplete='off' autofocus='autofocus' required='required'/>");
	    out.println("<button type='submit'/>发送</button>");
	    out.println("</form>");
	    out.println("</div></div>");
	    out.println("<div style='margin-top:160px;'><footer data-role='header' style='background-color:#fff;'> <div class='bar'> <div class='content center bar text-center'><font color='#000' size='6px'>版权归GreenTea所有</font> </div>   </div></footer></div>");
	    out.println("</div>");
	    out.println("</body>");
	    out.println("</html>");
	    out.close();
	}
	public void doPost(HttpServletRequest request,HttpServletResponse response)throws
	   IOException,ServletException{
		  doGet(request,response);
	  }
}
